<template>
  <a-card>
    <div :class="advanced ? 'search' : null">
      <a-form layout="horizontal">
        <div :class="advanced ? null: 'fold'">
          <a-row >
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="规则编号"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-input placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" >
            <span style="float: right; margin-top: 3px;">
          <a-button type="primary">查询</a-button>
          <a-button style="margin-left: 8px">重置</a-button>
        </span>
          </a-col>
        </a-row>
        </div>
       
      </a-form>
    </div>
    <div>
      <a-space class="operator">
        <a-button @click="addNew" type="primary">新建</a-button>
      </a-space>
      <standard-table
        :columns="columns"
        :dataSource="dataList"
        :rowKey="(record,index)=>{return record.id}"
        bordered
        @clear="onClear"
        @change="onChange"
      >
      
        <div slot="action" slot-scope="{ record}">
          <a style="margin-right: 8px">
            <a-icon type="edit"/>新增
          </a>
          <a style="margin-right: 8px">
            <a-icon type="edit"/>修改
          </a>
          <a @click="deleteRecord(record.key)">
            <a-icon type="delete" />删除
          </a>
        </div>
        <span slot="tags" slot-scope="{ text }">
          <a-tag :color="text === 'CATALOG' ? 'volcano' : text === 'MENU' ? 'geekblue':'green'">
            {{ text === 'CATALOG' ? '目录' : text === 'MENU' ? '菜单':'按钮' }}
          </a-tag>
        </span>
        <template slot="statusTitle">
          <a-icon @click.native="onStatusTitleClick" type="info-circle" />
        </template>
      </standard-table>
    </div>
  </a-card>
</template>

<script>
import StandardTable from '@/components/table/StandardTable'
import { listMenu } from "@/services/menu";
const columns = [
 
  {
    title: '菜单名称',
    dataIndex: 'name',
    key:'name',
  },
  {
    title: '菜单类型',
    dataIndex: 'type',
    key:'type',
    scopedSlots: { customRender: 'tags' },
  },

  {
    title: '状态',
    dataIndex: 'visible',
    key:'visible',
   
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key:'createTime',
    sorter: true
  },
  {
    title: '更新时间',
    key:'updateTime',
    dataIndex: 'updateTime',
    sorter: true
  },
  {
    title: '操作',
    scopedSlots: { customRender: 'action' }
  }
]

const dataSource = []

export default {
  name: 'MenuList',
  components: {StandardTable},
  data () {
    return {
      advanced: true,
      columns: columns,
      dataSource: dataSource,
      dataList: [],
      selectedRows: [],
      queryParams: {
      },
    }
  },
  authorize: {
    deleteRecord: 'delete'
  },
  created(){
    this.getList();
  },
  methods: {

     getList() {
    
      listMenu(this.queryParams).then(response => {
        console.log("获取数据的啦",response.data);
        this.dataList =  response.data.data;
      });
    },

    deleteRecord(key) {
      this.dataSource = this.dataSource.filter(item => item.key !== key)
      this.selectedRows = this.selectedRows.filter(item => item.key !== key)
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    remove () {
      this.dataSource = this.dataSource.filter(item => this.selectedRows.findIndex(row => row.key === item.key) === -1)
      this.selectedRows = []
    },
    onClear() {
      this.$message.info('您清空了勾选的所有行')
    },
    onStatusTitleClick() {
      this.$message.info('你点击了状态栏表头')
    },
    onChange() {
      this.$message.info('表格状态改变了')
    },
    onSelectChange() {
      this.$message.info('选中行改变了')
    },
    addNew () {
      this.dataSource.unshift({
        key: this.dataSource.length,
        no: 'NO ' + this.dataSource.length,
        description: '这是一段描述',
        callNo: Math.floor(Math.random() * 1000),
        status: Math.floor(Math.random() * 10) % 4,
        updatedAt: '2018-07-26'
      })
    },
    handleMenuClick (e) {
      if (e.key === 'delete') {
        this.remove()
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .search{
    margin-bottom: 4px;
  }
  .fold{
    width: calc(100% - 216px);
    display: inline-block
  }
  .operator{
    margin-bottom: 18px;
  }
  @media screen and (max-width: 900px) {
    .fold {
      width: 100%;
    }
  }
</style>
